package com.geaosu.kotlin.utils

import android.content.Context
import android.content.SharedPreferences
import androidx.appcompat.app.AppCompatActivity

/**
 * sp工具类, 单例模式
 */
object SPUtils {
    val SP_NAME = "Settings.config"

    fun getInstance(activity: AppCompatActivity): SPUtils {
        activity.getSharedPreferences("Settings.config", Context.MODE_PRIVATE)
        return this
    }

    fun putString(activity: AppCompatActivity, key: String, value: String) {
        val sp: SharedPreferences = activity.getSharedPreferences(SP_NAME, Context.MODE_PRIVATE)
        sp.edit().putString(key, value).apply()
    }

    fun getString(activity: AppCompatActivity, key: String, defaultValue: String): String? {
        val sp: SharedPreferences = activity.getSharedPreferences(SP_NAME, Context.MODE_PRIVATE)
        val str: String? = sp.getString(key, defaultValue)
        return str
    }

    fun putBoolean(key: String, value: Boolean) {

    }

    fun putInt(key: String, value: Int) {

    }

    fun putLong(key: String, value: Long) {

    }

    fun putFloat(key: String, value: Float) {

    }

}